FROM alpine:latest

# set env
ENV HOME /root
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV GOROOT /usr/lib/go
ENV GOBIN $GOROOT/bin
ENV GOPATH /root/go
ENV PATH $PATH:$GOBIN:$GOPATH/bin

# install pagkages
RUN apk update
RUN apk upgrade
RUN apk add vim
RUN apk add ncurses-dev
RUN apk add tolua++
#RUN apk add exuberant-ctags
#RUN apk add pandoc
RUN apk add lynx
RUN apk add lua
RUN apk add go
RUN apk add libc6-compat
RUN apk add git
RUN apk add curl

RUN mkdir -p /root/go/bin
RUN mkdir -p /root/go/src
RUN mkdir -p /root/go/pkg

RUN ln -s /usr/include/lua5.2/ /usr/include/lua
RUN ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/lib/liblua.so

# build and install vim
#RUN git clone https://github.com/vim/vim.git
#RUN cd vim && ./configure --with-features=huge --enable-luainterp --enable-gui=no --without-x --prefix=/usr

#RUN cd vim && make -j`nproc` VIMRUNTIMEDIR=/usr/share/vim/vim74
#RUN cd vim && make install

# get go tools
#RUN git clone https://github.com/golang/tools.git /root/go/src/golang.org/x/tools
#RUN git clone https://github.com/golang/lint.git /root/go/src/golang.org/x/lint
#RUN go get -u golang.org/x/tools/cmd/godoc
RUN go get -u github.com/nsf/gocode
RUN go get -u github.com/derekparker/delve/cmd/dlv
RUN go get -u github.com/rogpeppe/godef
RUN go get -u golang.org/x/lint/golint
#RUN go get -u github.com/golang/lint/golint
RUN go get -u github.com/kisielk/errcheck
RUN go get -u github.com/jstemmer/gotags
RUN go get -u golang.org/x/tools/cmd/goimports
#RUN go get -u golang.org/x/tools/cmd/oracle
#RUN git clone https://github.com/golang/tools.git /root/go/src/golang.org/x/tools
#RUN git clone https://github.com/golang/lint.git /root/go/src/golang.org/x/lint

RUN echo "export GOROOT=/usr/lib/go" >> /etc/profile
RUN echo "export GOBIN=\$GOROOT/bin" >> /etc/profile
RUN echo "export GOPATH=~/go" >> /etc/profile
RUN echo "export PATH=\$PATH:\$GOBIN:\$GOPATH/bin" >> /etc/profile
#RUN source /etc/profile

RUN curl https://glide.sh/get | sh

#RUN mv $GOPATH/bin/* /usr/local/go/bin

# add dev user

RUN mkdir -p /project

RUN adduser dev --disabled-password --gecos ""
RUN chown -R dev:dev $HOME /project
RUN echo "ALL            ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers

# cleanup
#RUN rm -rf $GOPATH/src/* $GOPATH/pkg

#RUN apt-get remove -y ncurses-dev
#RUN apt-get autoremove -y
#RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /vim

#USER dev

# install pathogen
#RUN mkdir -p $HOME/.vim/autoload $HOME/.vim/bundle && \
#curl -LSso $HOME/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

# install vim plugins
#RUN git clone http://git@github.com/farazdagi/vim-go-ide.git $HOME/.vim_go_runtime
#RUN sh $HOME/.vim_go_runtime/bin/install
#RUN mv $HOME/.vimrc.go $HOME/.vimrc
# RUN vim +GoInstallBinaries +qall!

#VOLUME /project

#WORKDIR /project

#CMD /bin/bash -c /usr/bin/vim
